<template>
  <div class="login">
    <div class="container">
      <a href="/#/index"><img src="/imgs/login-logo.png" alt=""/></a>
    </div>
    <div class="wraaper">
      <div class="container">
        <div class="login-from">
          <h3>
            <span class="checked">账号登陆</span>
            <span class="space">|</span>
            <span>扫码登录</span>
          </h3>
          <div class="input">
            <input type="text" placeholder="请输入账号" v-model="username" />
          </div>
          <div class="input">
            <input
              type="password"
              placeholder="请输入密码"
              v-model="password"
            />
          </div>
          <div class="btn-box">
            <a href="" class="btn" @click="login">登录</a>
          </div>
          <div class="msg" @click="register">
            手机短信登录/注册
          </div>
        </div>
      </div>
    </div>
    <div class="fotter">
      <div class="fotter-link">
        <a href="https://www.imooc.com/u/1343480" target="_blank"
          >河畔一角主页</a
        >
        <span>|</span>
        <a href="https://www.imooc.com/u/1343480" target="_blank"
          >React全家桶课程</a
        >
        <span>|</span>
        <a href="https://www.imooc.com/u/1343480" target="_blank"
          >微信支付专项课程</a
        >
        <span>|</span>
        <a href="https://www.imooc.com/u/1343480" target="_blank"
          >配套课程：Java通用型支付+电商平台双系统实战</a
        >
        <span>|</span>
        <a href="https://www.imooc.com/u/1343480" target="_blank"
          >Vue全栈课程</a
        >
        <span>|</span>
      </div>
      <div class="copyright">
        Copyright ©2020
        <span class="domain">mi.futurefe.com</span>
        All Rights Reserved.
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex';
export default {
  name: "login",
  data() {
    return {
      username: "",
      password: "",
      userId: "",
    };
  },
  methods:{
    login(){
      let { username,password } = this;
      this.axios.post('/user/login',{
        username,
        password
      }).then((res)=>{
        this.$cookie.set('userId',res.id,{expires:'Session'});
        // this.$store.dispatch('saveUserName',res.username);
        this.saveUserName(res.username);
        this.$router.push({
          name:'index',
          params:{
            from:'login'
          }
        });
      })
    },
    ...mapActions(['saveUserName']),
    register(){
      this.axios.post('/user/register',{
        username:'admin1',
        password:'admin1',
        email:'admin1@163.com'
      }).then(()=>{
        this.$message.success('注册成功');
      })
    }
  }
};
</script>

<style lang="scss" scoped>
@import "../assets/scss/mixin.scss";
@import "../assets/scss/config.scss";
@import "../assets/scss/base.scss";
.login {
  .container {
    img {
      width: auto;
      height: 100%;
    }
  }
  .wraaper {
    background: url(/imgs/login-bg.jpg) no-repeat 50%;
    height: 568px;
    .container {
      height: 100%;
      position: relative;
      .login-from {
        box-sizing: border-box;
        width: 410px;
        height: 510px;
        background-color: $colorG;
        position: absolute;
        top: 30px;
        right: 0px;
        padding: 0 31px;
        h3 {
          text-align: center;
          margin: 40px auto 49px;
          span {
            font-size: 24px;
          }
          .checked {
            color: $colorA;
          }
          .space {
            margin: 0 40px;
          }
        }
        .input {
          display: inline-block;
          width: 348px;
          height: 50px;
          border: 1px solid #e5e5e5;
          margin-bottom: 20px;

          input {
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            border: none;
            padding: 18px;
          }
        }
        .btn-box {
          width: 348px;
          height: 50px;
          .btn {
            width: 100%;
            height: 50px;
            text-align: center;
            line-height: 50px;
            font-size: 16px;
          }
        }
        .msg {
          color: $colorA;
          margin-top: 10px;
          font-size: 14px;
        }
      }
    }
  }
  .fotter {
    color: #999;
    font-size: 16px;
    text-align: center;
    margin-top: 100px;
    .fotter-link {
      margin-bottom: 13px;
      a {
        color: #999;
      }
      span {
        margin: 0 5px;
      }
    }
  }
}
</style>
